<?php
/*
 * 更新数据的处理文件
 * @author  Mark
 * @package ixdcw
 * @file    html.inc.php
 * @time    12-12-13 下午4:03
 */
defined('IN_IXDCW') or exit('Access Denied');
$menus = array (
    array('更新网页', '?moduleid='.$moduleid.'&file='.$file),
    array('模块首页', $MOD['linkurl'], ' target="_blank"'),
);
$this_forward = '?moduleid='.$moduleid.'&file='.$file;
switch($action) {
	// 更新内容页
	case 'show':
		// 是否更新
		$update = (isset($update) && $update) ? 1 : 0;

		// 类别更新
		$catid = isset($catid) ? intval($catid) : '';
		$sql = $catid ? " AND catid=$catid" : '';

		// 最小的更新id
		if(!isset($fid)) {
			$r = $db->getOne("SELECT min(itemid) AS fid FROM {$table} WHERE status>2 AND islink=0 {$sql}");
			$fid = $r['fid'] ? $r['fid'] : 0;
		}

		// start id
		isset($sid) or $sid = $fid;

		// terminal id
		if(!isset($tid)) {
			$r = $db->getOne("SELECT max(itemid) AS tid FROM {$table} WHERE status>2 AND islink=0 {$sql}");
			$tid = $r['tid'] ? $r['tid'] : 0;
		}
		if($update) {
			$do = new InformationModule($moduleid);
		}
		isset($num) or $num = 100;
		if($fid <= $tid) {
			$result = $db->query("SELECT itemid FROM {$table} WHERE status>2 AND islink=0 AND itemid>=$fid {$sql} ORDER BY itemid LIMIT 0,$num ");
			if($db->affectedRows($result)) {
				while($r = $db->fetchArray($result)) {
					$itemid = $r['itemid'];
					 $do->update($itemid) ;
				}
				$itemid += 1;
			} else {
				$itemid = $fid + $num;
			}
		} else {
			if($update) {
				$all ? msg('', '?moduleid='.$moduleid.'&file='.$file.'&action=index&all=1&one='.$one) : dmsg('更新成功', $this_forward);
			}
		}
		msg('ID从'.$fid.'至'.($itemid-1).$MOD['name'].($update ? '更新' : '生成').'成功'.progress($sid, $fid, $tid), "?moduleid=$moduleid&file=$file&action=$action&sid=$sid&fid=$itemid&tid=$tid&num=$num&update=$update&all=$all&one=$one");
	break;
	// 条目
	case 'item':
		$catid or msg('请选择分类');
		msg('', '?moduleid='.$moduleid.'&file='.$file.'&action=show&catid='.$catid.'&num='.$num);
	break;
	// 显示
	default:
		$r = $db->getOne("SELECT min(itemid) AS fid,max(itemid) AS tid FROM {$table} WHERE status=3");
		$fid = $r['fid'] ? $r['fid'] : 0;
		$tid = $r['tid'] ? $r['tid'] : 0;
		include tpl('html', $module);
	break;
}